/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import Entidades.Propietario;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

public class PropietarioDAO {

    public void tabla(Propietario propietario, Connection conexion) throws ClassNotFoundException, SQLException {

        Statement stmt;
        ResultSet rs;

        stmt = conexion.createStatement();
        rs = stmt.executeQuery(propietario.getTabla());

    }

    public void insertar(Propietario propietario, Connection conexion) throws ClassNotFoundException, SQLException {

        PreparedStatement pstmt;

        pstmt = conexion.prepareStatement("INSERT INTO CLIENTES VALUES(?,?,?,?,?)");
        pstmt.setString(1, propietario.getDni());
        pstmt.setString(2, propietario.getNombre());
        pstmt.setString(3, propietario.getApellidos());
        pstmt.setString(4, propietario.getFecha());
        pstmt.setInt(5, propietario.getSaldo());

        pstmt.executeUpdate();

    }

    public ArrayList select(Connection conexion) throws ClassNotFoundException, SQLException {

        Statement stmt;
        ResultSet rs;

        ArrayList list = new ArrayList();
        stmt = conexion.createStatement();
        rs = stmt.executeQuery("Select * from Clientes");

        while (rs.next()) {
            list.add(rs.getString(1));
            list.add(rs.getString(2));
            list.add(rs.getString(3));
            list.add(rs.getString(4));
            list.add(rs.getString(5));
        }

        return list;
    }

    public void delete(Propietario propietario, Connection conexion) throws ClassNotFoundException, SQLException {

        PreparedStatement pstmt;

        pstmt = conexion.prepareStatement("DELETE FROM CLIENTES WHERE nombre = ?");
        pstmt.setString(1, propietario.getNombre());

        pstmt.executeUpdate();

    }

    public void actualizar(Propietario propietario, Connection conexion) throws ClassNotFoundException, SQLException {

        PreparedStatement pstmt;

        pstmt = conexion.prepareStatement("UPDATE CLIENTES SET NOMBRE = ?,APELLIDOS = ?  Where Nombre = ?");
        pstmt.setString(1, propietario.getNombre());
        pstmt.setString(2, propietario.getApellidos());
        pstmt.setString(3, propietario.getNombre2());

        pstmt.executeUpdate();

    }
}
